﻿/*

Sums 
Time Limit:1000MS  Memory Limit:32768K


Description:
You are given K integers and I want to know the SUM of the biggest TEN numbers. Can you write a program and tell me the result?

Input:
The input are divided into two parts: The 1st line: An integer(0<N<=10), which means there are N test cases in the input.
The 2nd-(N+1)th line: each line contains a test case. For each line, the first number K(10<=K<=100000) means there are K integers in the line, then followed by K integers, the maximum number is less than 100,000 and the minimum number is more than -100,000. 
Output:
For each test case, you should output a line which contains only one integer: the answer of the test case. 
Sample Input:
2
11 1 1 1 1 1 1 1 1 1 1 10
12 -100 1 2 3 4 5 6 7 8 9 10 -1
Sample Output:
19
55
*/
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

#define TEN 10
int main()
{
	int n;
	cin >> n;

	while (n--)
	{
		int k;
		cin >> k;
		size_t heap_size = k - TEN + 1;
		if (k<10 || k>100000)
			return -1;

		bool flag = true;
		vector<int> heap;
		vector<int> maxies;	//保存TEN个最大值
		while (k)
		{
			if (flag && heap_size == heap.size())
			{
				make_heap(heap.begin(), heap.end());
				flag = false;
				continue;
			}

			int elem;
			cin >> elem;
			heap.push_back(elem);
			--k;
			if (!flag)
			{
				//压入新值
				push_heap(heap.begin(), heap.end());
				//取最大值
				maxies.push_back(heap.front());

				//交换首尾值并弹出最末尾值, 保持堆长度
				pop_heap(heap.begin(), heap.end());				
				heap.pop_back();
			}
		}

		maxies.push_back(heap.front());

		int sum = 0;
		for (vector<int>::iterator it = maxies.begin();
			it != maxies.end();
			++it)
			sum += *it;		
		cout << sum << endl;
	}

	return 0;
}